package com.gouqi.tools.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gouqi.gouqitoolscommon.model.entity.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户数据库操作
 */
public interface UserMapper extends BaseMapper<User> {

    /**
     * 通过userAccount获取角色信息
     *
     * @param userAccount
     * @return
     */
    @Select("SELECT NAME FROM role WHERE id IN (SELECT roleId FROM role_user WHERE userId=(SELECT id FROM USER WHERE NAME=#{userAccount}))")
    List<String> getUserRolesByUserAccount(String userAccount);

    /**
     * 通过accessKey获取角色信息
     *
     * @param accessKey
     * @return
     */
    @Select("SELECT NAME FROM role WHERE id IN (SELECT roleId FROM role_user WHERE userId=(SELECT id FROM USER WHERE NAME=#{accessKey}))")
    List<String> getUserRolesByAccessKey(String accessKey);
}




